{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic Operations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "x, y, z = symbols(\"x y z\")\n",
    "init_printing()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Substitution\n",
    "\n",
    "`Substitution` 替换表达式中所有的变量为具体的实例或者其他变量名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF0AAAAVCAYAAAAkeuLCAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEEUlEQVRYCc2Z7VEbMRCGL4wLCKGCOB3wUQHQASEVhHQAwy/4lzEdgCvIQAeQCjymA9NBiDtw3kdohe58OmzZ5G5nNNLtl1arVysZitlsVnStXVxc9HNiyrXLmWsVm42iY3R5eXmqkLYzw+p7+0zz/2P2gR3rCilhR4plT/1Zbkw+6U/q73J9rNNOcQCgW7Udjaf47kzSFdBHxfNb/Q6BrULyMZb9vi1yFV85tn4tQ9k+q+2qkfhNi6enj67QQIFcrykY/ODvR64/JehAtpSrm2V9+OR+xU7juXLZpZp+nLPAuoR4P/jj9OQStqvYJ+ftRNKVHFD1lIwyT4C/4zzT97UK5cWjgiM5jaYciR8upEhn4nW+qL8V/8FsNKZ+kUT8GFK+id9UqzmKwYfGgfycJ2Iw10TfVyb0sqF6d5SN73v8HaotXR4qftb+6ZKuoPvyzOXzXWOXZPUkjoTyEnhUs1v4EJ5FovE9MrUrNZI8UM9iA+n7rdrKZZOq5+eyP1PjZcPlFJKuMUiGX0cAgzV0jqy88KSpPrMMpSAWQudOiw8Jd9yi4HlHotkUkrersdl6lSKcFmNUevS56UskP4Bh5JlsZHVueLUnRHz8VeMQq33q+QSRsBhBhfgkylCPPE5AiFx6nAK+KSEgksX+VU8y7tXYqLfe3Z+kZ5urYaBn2dqGgeqfQfIyAMlVnqmwQcTcSPLPCas7EcRUSF53SllzXUlrnMuEPQ0ssD/GrOlNpy4xps7GQNTuczUWwh3BKbhJBC9xmmTj5lOPL1Ab6rN4zAcvhfTURsrklVJxiU/Z4slYAuOrZf5oQ6Z2ZLmoUmQ6LDJFlCe3OepBPMnfVAMpJ/q2Tamzx3+Tb1AFuqaRMRsxFe8x4sVD/M2VrFihrfGGXwiBU4/nSPIjvzAWXLogUZaMxUMcUxLLS8ORZCQFdFIiav2/aLrk2GnyrFKHzDbeBE31HB2QXrUx21Z7kA6BJI5SSBhMfVMeDEn7GvODo4pYdHi5mB6vjSpq+U6VAYncHHsMElRKnvyz0TTujBRx0prkKbt35/eYQYugNHzWkDcvwYJq6BoZA/Ucb2SUDpODQL4tofBBdvxrcEvf1PVS4sSLieSknozocRETGxvM3WOl0OYVa47YFPRbIcXKaw+w2QkfiwcwR535W7r+Fj5R217k79TSG6iNU7qS9dUmKfkifNkfqZ0uorusjpWXVtBQmRRUzj3PhA5OGz/cHGkMeiiDqacieu63A4MViFNLWzt1JulKJmWJe4WSFRNl4lfEGGrME9Te75HIlUHs8ROelyWFBT9k/7Cqj9RUrqanhC3wudCphfErCdSSRP5ESi0H+U21nLsBP52lzvwTwzKkhILUgxyUyYayA0KbLm2bqrX+HwtagnZzAZsqAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\cos{\\left(y \\right)} + 1$"
      ],
      "text/plain": [
       "cos(y) + 1"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 替换为其他变量名\n",
    "expr = cos(x) + 1\n",
    "expr.subs(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAkAAAAOCAYAAAD9lDaoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA30lEQVQoFW2RMRKCMBBFg3qAjEeA1orRnsIjWNupR6CEVm8gpa2tnRY0tt5AjoDeIL4fBycqf+ZPsn//bnYhcs6ZsixjY0wOhSlsYY5+kzCEMmwRllmWnWBV1/UE7cB5JW4GMsAV/IACdX3Co0SZ5vBBwkoIcOFu0WOZFDQEquyDNRq8j0VR3CEp55/7q6ZriqiF/MZ6rg8auMK8UzJSuxAk9oo5N53+1YnE+tegeNS5MSy4J2EH7prrPTiBBp1xdr9GOUGFbcSacp+hvleIMUFKYaLntImMfh7OEP4HvwBvn1+w+m4NrAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle 2$"
      ],
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 替换为具体的值 比如: x = 0\n",
    "expr.subs(x, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAQCAYAAAD52jQlAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABcUlEQVQ4EaWTO1ICQRRFp5QFIGaGLgE0nwB3gOUKlNAMi2gms2AH6gos3AEG5Ao7kNCQYgfjOc0wdhmgg6/q9uv3u/36lxRFkdRFlmVdMACTuBZ7qn2Q7CcXeZ6PKe2hm1Kg26gz57VJKT6l7h7dRS/Ra4kQ7XcnDYc6AsnSfHQf9RLVnjOfatfuNCJxu4Gk9Nnpq/P/kFq/cqBrCZvohXbt7VtUyh26D9EcfQkCobGKlKC3eKMT8XyugZdyBZQ3csIZlrmLyJb0IWQxxNsfkTQWEoAn0MW2Ixccga0Y62kQd+st9KO2EjrFYYdxkTGLJFRaII4/66NugD5Gd9Df4g/gJ7R//gx889hXZx62z0rVIZfLuSW72UviMw0ELCChUj1sfD6X8B03od1jo0yekOZF+Xj9KQnz8HOcI0Ps7fluPDtGO7UzsaLQbnzQaxAEnzFfw5/lME3TT7K93SPQgWQ4m80+wC04wVfgq44C+1f5ApJ+40e6xDn1AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle x^{y}$"
      ],
      "text/plain": [
       " y\n",
       "x "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 替换为其他表达式\n",
    "expr = x**y\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACQAAAAYCAYAAACSuF9OAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACBklEQVRIDcWWSzJDURCGb7AAj5lh7CCYZ8AOKCvA0CzKKJmp2AFWoGIHMcjcYwcxNEN2EN93nJO6RQl5XLer/nTf7ut2n34dleFwmJVBrVZrD79VfSNfRN5ZUCiRnvC9oX+CqslLC4gAbvG/D7oGAu2AbmkBhRCybAt+F+Vd+EOlrB4yCLLUiMEM4Jc8V5aiYu6Mj9uwlsEeeQU63UVvmbJof4bfAhv8Sn2RJavhSCf2iIEoP4NEywjb6I/gVfixhsJLhqNQFngYbZ2Oo8IylALBuc0aGhedpRlLU2co59AeaQNTbhna2OwNS9WJujV4Hzygd/f8TE7ZpGg2mw1Q9e/gHdCN8iPy3qTfy78/7ZQNzEI8pllJy+3w1wz8nJtgmbpk6bsE4GW4OWsg6XszNTVBhPsnBQN398xEEwekU/AevR7A800adsksEY1KhhN7wSUlbYND4Il1Kt3zjlvV966BfWMfOdZuYifpHPsAPj2lDmc6LnOyU+T0NNRpA/1kL5KHknEqM+MuyZNLzH8RpFXw1R4Mc/+JGajlT002uuAxr/svOWUo35ge2lv6Zu6n/8MHv00Z5TMYKZUrQ7csPtXF/i5FR9453kFegmF0kdMmNoIznk8ViiYzZEbEWwzuDXk0uui03YN/ocV6vf6CJ6doBXgFnPV6vT44AevohuhG5eO5UPoAzC3bGWpY7HsAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle x^{x^{x^{y}}}$"
      ],
      "text/plain": [
       " ⎛ ⎛ y⎞⎞\n",
       " ⎜ ⎝x ⎠⎟\n",
       " ⎝x    ⎠\n",
       "x       "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = expr.subs(y, x**y)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC0AAAAdCAYAAAA+YOU3AAAACXBIWXMAAA7EAAAOxAGVKw4bAAACJUlEQVRYCc2YPVICQRCFQTkAamaIN8AyJ4AbYHkCNDTDIoLMgiPoCSy8AQbkCjeA0EzkBvi9ZZqaklp+VpedrnrbvT2w+3i+mdk1v1gsciFGp9MpwasKLsAXmIMa/esjilCjDMEnyA2AyKqeimw+VKVFTgHZpsu9qMEhWKWNLBxr4E2E6dWVg1UagrJFHxTBGZiAD/rjzEhz89iJBrmNkaU9YifaRsYMZqa0EUPxtYlmY3E5M6WNLMTWJlocWeunpvQ2zzIeO9GMXGzWOp0G2u12XdclV8HA1d3/uFdqSptKZgPyanOwsaQ5NU8bWYjt7dltPyax0h4pPdB0wR3QRtBlbAqSe5aLbIwkHsOjTVByPu17nh1RR15Oct1dv1PY+IviB+dS0w1LXamqaNAfL8v0jontYZQgqQfyy0OQtXv+aSJCtKwLGWFyyS6cZt6btIiBb0fqhuzbQZMx9djbHhCWh5+BfCxfa0nT65AeHx8Zn5NTjRVpR+bW3e2K3AD6c0tNxTufeV2W2R59e2h97QkiCKRmlfMHcrT+koOIiDTEpLA2CD/0amPKnlL/Hvc/e9jabRBlf2HXZgFGfi+k2pT2VwCppv83vBxWvt3v5ns6+hZWEWGFWSNHrygs29kfC46M3no1EfWqHq211LZNi2WLc03IIEJKS1lh5n7AjHq11tLTmFaTYOK4Uql8wkarwwnQM0RrOBxOwD04p7egt7IK55nHD3YlV1p9DZ0RAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle x^{x^{x^{x^{x}}}}$"
      ],
      "text/plain": [
       " ⎛ ⎛ ⎛ x⎞⎞⎞\n",
       " ⎜ ⎜ ⎝x ⎠⎟⎟\n",
       " ⎜ ⎝x    ⎠⎟\n",
       " ⎝x       ⎠\n",
       "x          "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = expr.subs(y, x**x)\n",
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果我们想要化简某些表达式, 也可以用 `subs` 来替换要化简的部分. 但是 `sympy` 提供了更为简单的方法, 在后面的章节会涉及."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARMAAAAYCAYAAADZGRnPAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIKUlEQVR4Ae2c7XEUORCG11sOwHARHGRg7AgwGRiIAJPBXfmX/e8KMgAiuIMMgAhsnMGRwcFm4HufsVrMjqVZzUra3bG3q7TSSN2t/pBaHzP2zvX19WQLWwtsLRC2wPn5+Z5aTl3rI5e/Uv0sTHF/a3fvr+pbzbcWSLLAGwWO14ap8juVvyk9trptfmOB6dYQWwtsLdBrgRMFkKMWxhuVH6luv1W3LcoCow8mcqptPQc7NId2cGeFCXJlz6UvrM4ms2NXcpkrYI69c2hz5R5CP+pgIiP/IWVzVghWGHiMCgrojb6j1H3VjpKt3yu170cILt9Vd5UqSwF/jcJXO1zASllW9z+dcQ6U/+B5iMEcrc8cT86W8HnvGwoVxPNYrA6Vm9xLcRY9wYTB8WkpBismKqU3Ym+C7pKh+Nir5RLJysL1UemJyu0AE+1SeHdynIZssXN2doYzuWR6bhZRmXMhk+yZyl+sfkguOs6Zn5WI7P4CawiPGK74ccP+VfmTGM6QevEh6D1VnjRAhvAuiVtab2Rbp+7qu8rYK2lz4+Vk5f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7Fu6j1L+2nhfjXZngsddtD5SHv3jvL6RITounfniMmt309dHjbZcvZFprLrXsGdtnrn+Gouv/geolaDr4kLRDwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle 2 \\sin{\\left(x \\right)} \\cos{\\left(x \\right)} + 2 \\cos^{2}{\\left(x \\right)} - 1$"
      ],
      "text/plain": [
       "                       2       \n",
       "2⋅sin(x)⋅cos(x) + 2⋅cos (x) - 1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = sin(2*x) + cos(2*x)\n",
    "expand_trig(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOEAAAAVCAYAAACwsIl1AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAG10lEQVR4AdWb23UUORCGhzkOwEAEazJY7AgwGRiIAMhg9/Bkv0IGQAYLGRgiAJwBZLBmMvD+n1YlenpKPX2RTHedI+tWVV31t0q3Hq9ubm5WS07n5+dHY+2fIjv2maXkpto+Vb6UH3PScxuYeM9YrxZMFxcXf8n8Pye4cBR1TFBx+6IF/MboRfpeC+1CmPYxbwf3O8xEMuBI0n9HDcfKr6mr/Sq2Dc6izm9Rz7vBCvYISP+ZWE6Um917JPxuyRPIP5R/9Dnm1VrKb7xamu+13kQOU7UXjwsP9zssj+p4rQc+MSdVfq0yg/Oxyp+sfUguuVPxXyq9U/nlENl9vNJ3KJ7Pyh/u4+3TLz1MFo+Ub/rw/y6e0n7jx1J8r4V5DlO1V4kL86OJ+1qNBNxz6yQXA6sLA/ID9TEkHQTvXeVFAzDags1vx9iVkUEXOudOpf3G30m+6/2eKr2YO3Ad9uUwpb14XDTsSLgThKxYPwUkq0uTCKJDtTMjjCLJ1lpZnkp3sS1u1IXONgaj/K4oVNRv7CzgO5jNHbeuV5LDtFpctHEnCAk2zkS5gJkVwLITcH7gSG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iPrOJLc1Y7Fy/o/5qvqO/BgkTsJotpvgsGzvjQv1FcF9LEQOaAycK3zYSbS9Vzw1aBvSheJpEPV3Fx442D80M+LHEiztxhBnopOtoF4M22a42+nbOa2ozYkXnbJsjzjbsDNLkA6PqbMWxCXqkxMdfXl6T4OFm1Pj6YtfUkfMbntq+N+0oWZ4tpnpXfeKiCO4HQpRg44FbgysibYMmVlPG4Gbla/7K5L7qnAvZcjEIGXhh5VCdwR0Aj+30b2I7Zzb46IcIfFZlq//f+usvulhR2kTwYxPArCSPHlZGePm0QHCmrSk8LUIOm12SLH79oc73yglYC3AmrrCCKucigj62mtYPttRtcurETrw5yvkNf1XfcwZNbRcmc8a0T1wUwT38F8VUMG9bXi+Pb3pPlOcmiUEmSQ+BQsB2nU8G6azBXNpvbJzqu+TPpGbMxUwNiAbrrIFpHyOauK/7CMyQhxUrXSAVsC98xyugp7aK0n5j71TfWdlt1a/tfw39NTDtY+cv3Of0n81DbNG/YF16/6U8RAe86EDXULnfxV/K7yX6Xgvzkpj2sbE95pa6EjLTcGb0zoZ9ZqEmDzpy588m31zKpfzGn6X5XusdlMS0j41buC/yTGhexn31qfLsj66N18slx2UUv/5xP014MnNom+o3PizV91r4l8C0j20e7v8BOMhGVdfwV7UAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle 2 \\sin{\\left(x \\right)} \\cos{\\left(x \\right)} + \\cos{\\left(2 x \\right)}$"
      ],
      "text/plain": [
       "2⋅sin(x)⋅cos(x) + cos(2⋅x)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(sin(2*x), 2*sin(x)*cos(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 1. 需要注意的是: `subs` 会返回一个修改后的对象, 而不会在原来的表达式上修改相应的表达式. \n",
    "2. 此外, SymPy 的表达式是不能改变的, 没有任何一个函数可以在原位改变表达式. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAOCAYAAAASVl2WAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAXUlEQVQYGWP8//8/Aww0NDQYAdmrgdgYyP4AEmcBMgSA9GwgfgfEJkCsBMRwAFIAUhkKEgGyy4AUyBQ4YIKzcDBGFUAChmA4MIIiCxjEoAgCxQkoLkD0PSA+B8SnAeDgGGsGGU5UAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle 1$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = cos(x)\n",
    "expr.subs(x, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADkAAAAVCAYAAAD8dkbIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADMklEQVRYCc2X7VEbMRCGLwwFOKGCOB0QUgG4AwIVQDoIk1/wFzogqSADHUAqIKEDu4MYd+A8j9Bq7sydMxjPcDsjr7TafW8/pL1zNZ/Pq76N09PT4ao+tdluVD2js7Ozr7i0/QK3hhmjQPQqSJzbx7Mt+HXx8JkTbG81yVjJ+o3Hog+EUwP8+AX/uA5/wPkDzi581qdKnuPU5ToCzBhiiVn1qZIPZP1tdnAtDLwHgN73opI4s4czk7VE1gQR82AzZDzIO2F5ZyGD3yEvTaCmM846H+BXyNNlV8bczqjT4ogpHSJfdtc+o1MwkkXtB1txjrPoE/yIMWQcZlnDzyyTiTlKQQKigRf1iHkKCq6jBjBh3DN0/ooxUgZPxPzGPcYFQ2fO4aO8HTpf6uuW+Q6yZfdRzIQB9xXzg2FgJ4y4e6UYNXyLsRfHVecNpq4YVZhlI3Wu0SkBZvkJXCdMgs7uMA/brFLVcUNW5+pP64KYg2UFUwMJGdxXTWC+a9kPVTEHm9khHbyIHTlyQRIQc/et9h2jQexZZWUeSTMrsE3Eo3LDMDEmYhnpaCRzUe839vXEekp8ZpLBPepdpM7QSuq89PeRtf6GTpcjGpkIybtnwnTcCoxxZNlRRKWbsL1f2PUa/VyQdS1T8gwysmQT6aLQ8Vh1kcc9JQNuRQ3WV4J36Zh1JKHNXvxl2MkGDAOU4qhWyAaOR/GTX+XTDRRmTMyW9+kJsb/PcF+9RkNRmb14sNUykOiC7s0Y35HpVCs+cskjHqclCfzB1gBsbPGMaD6RdNW+sa9vbWQlJ1ZS8lz7YVscVMja4xbHZZf5AbLFiqhjZw09H2oG6+S68xXBnra+GhbJ4BzTjGkySkDI3HvSJ5AFeZpuyhdPBrE114EukZesMTfbNpF4kGt1UgBwH2q1bd0R6BZzq9EZZLYTp3FlWIuR7jW8Ym0y7aw+w1eewZejy7pB7OnHqDf/JfkfOGZsr/o/ctHO/5ViKo/j2sjAKy2s2P8+Gp7jWnp/a9CbIDlaNij7glfgRZQxxBKzP0HmqGyAK79TM4ZMjPKRUBpPTeFVp7kKe1GF5zqDnW+IW3hpmP8AsdJ/5Wo5a9sAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\cos{\\left(x \\right)}$"
      ],
      "text/plain": [
       "cos(x)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`subs` 接受一个包含多个 `(old, new)` 对的列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABV0lEQVQ4EX2U7W3CQAyGATEAgg3SDfjYICP0Y4KWDUD8y7+KbgArlA3IBqiMkA2g2SA87+mMLscFS8bO69eOnfPRb5qml5KiKKbgS+wyjoNtPXbBvqBbsErYQD8d8gs+jmMk/oGdsGv0B3+NHvEzcZMFCa4UjAX8C2yEPVgMv8bX807YQ0EIGlUkaSxvAOcY5PmE5uSOHgoS+CCwTyQJytFrImYvz1sFKaRRXetxkt4eY4nn8b0gCRmEGutOK0X2mHUTUqzr1shaka5Rw+Rn/sR1SCGdXnLUINu6CKC7a+t1GfhRtQpdo7os4jZq6lsaVg1h69stSNAih6L1yTxeYbXApbCQ5H3rsBxCFEnaEvB/gBKr3TPRS+3aGSY7Q89wa/cNw0jgawwbxcEk6NCu2Ffj4Yvzjn4K68d/DhB0OHNUI0vUve6q7m3PF9jg6o9BskC/wd0NugEgSHPAFQjjDwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle 40$"
      ],
      "text/plain": [
       "40"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = x**3 + 4*x*y - z\n",
    "expr.subs([(x, 2), (y, 4), (z, 0)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAAAXCAYAAADwZlg5AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGsklEQVR4Ae2c63EUORCAF5cDwL4MIAMeGZgMjnMEQAZ3xT//c0EGhgh8XAb4IsCQwZEBxhn4vk9IU1p51p6dx652a7tK6DGafqm71dKseXBzczOrEU5OTh7B1++Ua8pDynPKKePfqHewIg2g76+UpysiNzkZZNGW3kZC2pjwinHtrCrYr4qbeWbe0f2O0t47TP0n1b+UA/s7mF4DUedPpqe0UgrvkOtNokj7jPZXyuM0Vku9VwsjLXycMnaejf9G+3vW3zUn1ABGe7Sl+n4dZUvacxN4xFh1QajanRNllemrKa6K3MHEGkD3pn4a64eJSa0Dvbvm5ToIL0uzWudMgmAoprPHlDPa22gsSdSaaneX99FJa+JrMC8tNqSzenwqN4PBtIYimMQ5EdSo+4a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+wvGtU9rYyd7pW2swpz48uZJkStr67zOAQebrQAb9GM6MuHdOxwTK24Y30jKb+BrTZqR2/D5jv+s6o1beBqzlHMmZq7tjgnRNct/QBXukuzTfvdLIr5m2cbOpEgHd1b13ajGmta3W074QBoBKfQ6D81idhDclxfxo154T0JS6kiD5jTCOxDgq3XRvAm4bmd8DGEGmrgxn1XICiX5uM7qzusLl+5dG7gtJAFGmdsKxdbZJsM/StrYfbYtoHlHxNGr0Pck6QGnFvRV3GfzpOHVItapnRUb0scX4wbtq5QXuwn3Ni5lUD8GbAMRCVPOqwnj1rl1GDz/Wtbqs8b6LLTnalABE2Rjb5RT4Dog6pj5SO+SzKdDHIOSOStkpDtSQwQlv8Bur4FaVhijGfpUsLmnUB/Ln4BheVmZ+vDxnzts0DvU5as4w6pvwGgN+0Jk0WkJ5VXJd2lVjdRNnKID+LNqSMXoRd7yfpxqhBqOEmzz+i79W9JX0z0yBmjEvc3xA63+09P9g7pTbQMXXQcN4smEspodFeOWuVUWPwe6Y35j8o6Y+Lb2U+PKsKop3csivG0/l742SDd7MtfSQP9tqYPykMa/Kg1v+mpCrrqIAZFsydeekLoUWsg08n1Th6XQYuwluOj813ib+tvy2y7bUJtxurUgMeA5qjwDIcYqxnlObnarRNncwCTpfB03Nub7670Ntm2UZNa7soczennwYwwiHpp6l2nj75yyzTqua2vB9X9781kO/7Cfw6RmylbLu0tsvyb/gcHCSkxFEMz5p+5B7i7NVoZJtl+x8rIhyvHno8yAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle - 4 x^{3} - 2 x + y^{4} + 4 y^{2} + 3$"
      ],
      "text/plain": [
       "     3          4      2    \n",
       "- 4⋅x  - 2⋅x + y  + 4⋅y  + 3"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 多个相同替换\n",
    "expr = x**4 - 4*x**3 + 4*x**2 - 2*x + 3\n",
    "replacements = [(x**i, y**i) for i in range(5) if i % 2 == 0]\n",
    "expr.subs(replacements)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Coverting Strings to SymPy Expressions\n",
    "\n",
    "`sympify` 可以将字符串转换成 `SymPy` 对象. \n",
    "\n",
    "> 注意: 是 `sympify` 而不是 `symplify` 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGwAAAArCAYAAACdO20ZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcklEQVR4Ae2a7VEbMRCGDUMBQAnQAR8dOB3ApAKggzD84y/pIKSDhA4gFRDoIJRg3IHzPopWI985YyHMnQ60M/LqZH3s7iutVrpbm81mo0plWeDy8nJPEv1U2ld+Gku3ET/UfH8WEDCbGv270kTpQGlHqUUVsJZJ+inwK+mY0ZX/IsYqa9F6q6QWFG2BCljR8LSFq4C1bVJ0SQWsaHjawlXA2jYpuqQCVjQ8beEqYG2bFF2SdQ7zh7wLr9mO5yf+LFG0wkMXLgswKX0lcM5MeeW/Kf+gtGtllb+NBXJd4qlAGkciXSm/o7KFp/OoXs2+0gK5K4zV9fuVY9fmDQtownPhy50id4nQg8oexe/Fv1KwtorbenXGCjsS78Ulalz2UXPRKMwzbvtO/F1R7goLRpBRcINHSvuhsMOMxgegc3EDbKT8qcpuxY+VbjoU582Hyt3DnGAyhpvJemi9t3mJ5OpnrISRc4h27KlMGqMfPmORrJUPnmcDZmCJf1KaKu35shyjsEpIOYSPn/rk2iNPTkdDaJPlEj0whPK4IosMcUnnXSut8dmntuJxVWarDRnfFQXApCQz3NzSofInSri8z0oQkYrtB5y5qA8PpP/DPhIKO85IhrGGJAg6U/46Hl7PL9ExblpMPgAmicJhWIrxxpPX1YDEKmKmYgQHmJ7nZrTKeyfJxEoHLCYbbnLRsSNZR7UvkhxgUpaVBSAx4VbMxW0r3/w/rtt7XjoAEmmkPLJzhglRovKD1xHd3DlMyhAwOGUpVP5WbFt8paG6+mOlsgqaxISAJv/Y3O+j2rlvHeZKlzyozbOq4AK3lLegKFtH9UFfv3yfYknEhAljJrVYUslWWLNTjGqra0kX6X9L+IV7nMpZEVxtudN8eo9ucrmgZ4FhcInoQbpZ8P+LdFT7qfpZ6QRWf47Ud/K3hhvWyLgaowhkAcZIZcwuOEIXQ14uF/go71ZSinCqW5SOkmctRW7qrKO0ErcCpoRbBXp+ijq50HNRYCGblwm5WEFN+Q68/Hf6b7A6eh0C4+AMUKQJisGVgvIq4797pVIJ182eG0gy42LRhdAeXYauY9BtQzkOnpxXUGokBVGSFUeAgLsByOAeqVMSSbZrpbGX10Tj/MgNjF3+DlpHUwq+ktv6uMOcvAybHXTkjDfkNqywEgi3FdxwCQL1IYMmLp7BonP2YLYnLi5CFF/ECuvDOKWN6cHiJiacOZXnsoJbp+DeCToqlWEBwOH+NpAAY7XheXgT7agCZpbonxP0PQukzYYoBEwcS3CXowpYwzo9PgLMk4D5317ugKx7WI8IpQwtAP+oHtd27jakrrAUq/VURyBxT4ortMixusSesEgdlmCDi4FwKV5dYqrpOq4nkNznDeJzbziqS+wYiJThBJL7VKMJFm0rYCkW7LCOQOKabjcGS3mCDvayCliHWCwdSqAQZByKhyDDNwJErqnKuPz1Qn1o5lcQr4nsDYPZg88n+ITDfQZfyuWvCfeROREhbs8+NYxtES5//wLs8KB9YF/lCgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle x^{2} + 3 x - \\frac{1}{2}$"
      ],
      "text/plain": [
       " 2         1\n",
       "x  + 3⋅x - ─\n",
       "           2"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str_expr = \"x**2 + 3*x - 1/2\"\n",
    "expr = sympify(str_expr)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAArCAYAAACXZ8NLAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACPElEQVRIDe2X21ErMQyGCXMKYEIFhA64dAAdQAlAB/CYvEIHQAUMdAAdcM7pAKiASwfh+8x62XiXrA3DE2hGkVaWf8uSbxlMp9OFJk0mkzW+L+F19JdmW9Sxn0YdOYT3mr5/bMSwhDiHn+ANeAS3qPL7R8Mp+okOSIN4QBrEvbZFf/h4gXfhAz4vtH1ADjzELwDqg/4f8Rc+8lsKoG9q1u8OXiGaxFvg/WjLBiUiUySZopQeNeBjKvIjpUMsmoVJabkyhLbsSKtOV8hRish3iDC2lYLuCUjUW0oJXcA4i5CasKRCa8YPAK6SFVyPKzCnfVtxXcQiUMcVGOHSqwlb3Azv67Ru/bzihrmpBlwoipROTtENsBIBkBbOvK7DgUoLJUC6Tp36AeBugECDeKBg9BBxgTsVpfnR8Za25rY8xhZJv0vab6JBWYM2jV/VS6efNd4vaFaaipx+eE4H4/F49o4uyl638++O6s7LV6zfsk57T37OyhFRxyeNZ62H9BH2+lBOZzW3+hWgN+du7IjuIX0Ib6PPHM7Rp2/6AoS7PnYAyKi9Ub0pOqkPdItezwB5bTTJCJewm5oW9YHa+Z7ORtZF6WDBZ25Ou1C0McgdYoQcdPn0RdrqA5B3vNOOK6LlUwwKggU6A7y+tlPUoukDFN5MyJm3VAqaHSlA4fndB+gAWaAA+YZabQKiWyhz26JeUDpamE1kWhgHcsu2aG5Oq0iu6ZVuxyG2NdpXW4gY+g4UK+0U678zDZAPD5RXAza9IHcmhWsAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle \\frac{19}{2}$"
      ],
      "text/plain": [
       "19/2"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(x, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "为了估计表达式的浮点数值, 可以使用 `evalf` 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
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mCC\n",
      "text/latex": [
       "$\\displaystyle 2.82842712474619$"
      ],
      "text/plain": [
       "2.82842712474619"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = sqrt(8)\n",
    "expr.evalf()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`evalf` 可以指定小数点后的精度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABBIAAAAPCAYAAABZX+yQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAXRElEQVR4Ae1d7ZEkNRItNtaAZc4CwINj8QA8WA4LAA8g+Mc/gvMAsIAPDwALgPUAzgJgPNh7T5OpVakl5cuaapa7WEXUSKV6evmp7K6anp5Xnj17tv0vt08//fSfOJ62NuD8Ec5v0P/Wzr/I8TX0vAan4iPIfR24t3F8g/GtsuYl5qUHru2Ba+Tli9pj1/bVX81/jdj81Tb8neRl/Pkic/hFyj47Xhmfny37Wnwv43Mtz77kfemBlx64hgf+n2qW6p+/+2vPQzfEFP3QznkjzpvFzzH/g2OUnkEG7lscb2Ic3mQa/kP0LnsnRuD7ERjq6w8TOGZ7867b/wT2i2bmBuP3MbfTE+e0/WPDPUb/B88x7zLs0l2H+c93E9v29QAr6Wmy3Re0ZRUHlZM8n+D4Hcc/cPD8W8i6iC3mQv9gLWNM3BfAo7tot5h/1WcVTmBop2S3YcP4JDllH7ld7CGDvljlb5gbqj0uF/iQ07HsVzqa7NDvKs7kSb5UOQ0XxhuyT89LcEp7jHazQVePDffaGzhYQ3cPNBP2kE/1pYSjjm0D/zJ/iTXMsqYDE9WNVGxcR0W26eh+96WjGkxbIj2JydSikM8VOll2xp/ZHCb3Mt6dz6e5DpwkG76R89fio9SDDVjPi5WOJUTARrHM+Lxw+g9wc+3qdSKS7VS1jzgdGOCk+JALPJKOwEnvnwwXvvaYbCWOcnwgW843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HmqvFx10Q+d1zbz/ZZVrbC2WI4nslW4yPrqMYHOkn7LBlHtzuKj5xvThj10DNTi3q6YXxU21XZwDGO4XtbU07y0TVkq3ZDT0lHs0fNYRUny76CjzKy1Vot7Ufz5agb5bCkZzIv1Zp1uj1JPUc+OmNuWdsSe2cDVq1ZYRxfefbsWTEOpPwtPhd444b63IT5HIXz7+r55Kp+5J8XcV4KFIZ8YkJjeYPKG/SfcK3/bwfE8yaeWD7hYaNRvLEtWPQSH3DUk0nDdoODDwv4xYK3nGgb5upNP+apI2+wKbc2nPMhietU523A3yz2n14gpweX8j8Dpj6YcALMSXoCJ8WBvAlO2vMJDvrG28j20D++mL3Jp7/ex/jib1gNI3FivWQ3cHJ8VE7TU/IRsWzgXuavYcLcyNijchLHJuqo+l3CmVzJl9Av5Mz6x+Rzr52Vl9K+NbmsA9xnv/Mc7S0cu3qQtQd41ZcSrmiFH+BV8letwdIep2zIDWNjOEm2YcN91uA4ZBvWf16AjmFeGi5jt4RVZVM+G/ChPw0TvkYCl/F5mOuNfopsKX+hY6b+SzqanlJ8GpuW9YU4Nuir7DNZtsqp4qCfVN+Ak3QELhMfdZ/JcTS7lT2h5pu8J0w2/UR92W5w7Op/mbUfYm7ItluMprIzsaGKwEs+MuzS7gOyJbsP6GjeX9Z/Nddl/5zto6Tdqi+l/egONJuW9U3R80BuqDXrVHsyegIr140kVqltUrw9jpC/3LsW52Wu/xfj3Zg0pGRKpgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068$"
      ],
      "text/plain": [
       "3.1415926535897932384626433832795028841971693993751058209749445923078164062862\n",
       "08998628034825342117068"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pi.evalf(100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果我们想要表达式的运算的结果的浮点数估计值, 可以像下面那样使用 `evalf` 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALUAAAAPCAYAAACiAo66AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGpklEQVRoBe2a3ZXWOAyGPzhTwDBbAWwH/HQAHcBSwUAHcLjjbg50AFTATwfQwQIdwFbATwezz5Oxso7jJMrdXKzO8diRpVeSLTnOB1fOz88Pl42eP39+A5/u0t4x/n3Z/Pvfn8u9AlfqpCaBXhR3f9D/SXsB73s2hIw+MsfgPaNp4w+az+/hf6IfiPF9Bu/LY6/7jcy13gT8m/Af0z9emH9V8U8YnyI7KRyeN30MDGQ38ZTNYiJnQYfv+uGz+zCuD89dQqYb+x5MZFPxtA4s2d4rB07kYKi+hfc1Hnp9a/sohJj4wviM/oM8ehf0C/092mZiI5PVd4Ni0zR14NmkPqYNtmHdoRmIdn/SavIEf1ozmrHFMFsE8eHr4yvGL9WhNwn+ob9Fq2Pc9BH5PXiay2I+BXtcH8aP0P1I/4AW6yNej2axo6Ofm5hFLrs+Kds9IXgzH5XDvsX7keaBNBQwvbI2D9g1mmBeVRJlF65OKnm/4bmIdeXyOKesfpFz4Vo6hfGsYuqLieZGDqeuPfNW8SfG3c2F/6TCaIdvYJwgMyS0k4xN/s+0sUjguRYZH1N4YGkni6ncI+R9UwW9K4N6fWJu7NFZij2LmY5nNFoGK7YnohtyJqZ7W7+RLMj6sJng+dDDHJKauQe02ekG72/aXRQFX6OsvhWn7BZZsT2anXYhhI+euhairUcmSm+BjNuND8r6mMUTN4upL5MYiGspnvD3sBF7FnNPPFnbKTn817b7Nx4uKsL3lnDPcY+Y6+55JLWv9J8dxVhQ59coq2+yWiS+To8rQE/g8Y3A3OwkhqfMWaXTDh8i87pl+gw/bPVi/FFkXCBp08edeClMhcD1pLpm77PE2A2XxvW5eJz8XYt9ExMbe9ZnYpiHRduN4JqcbyG/kyLfGtXFxy7mURXQoiYTJ0uT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b7PogDUl4Mdz8q07o1cImcFscXj386KjfBFkfs3j6kMX0rTLZXHxzT4xHP7fWoRd7FnNPPLgzo57tmRCMmRxxDYVCPx6sjJWb5F8PrPAmmON/aCogzxD6UQTv0J/Brzf8wLN3Xyu/vZsKnNH3ZFSuTjATvVfVLrQFdMp8e9eG/R8xb4J6ookviWehxM+HB8bjojGnv0t2Uz5m8bCj7Sym92aLIMg18F9SZ+sTAsytxs58ChO51PqEXfst2yGbkSv23RfphDbLv2Gm/FnC/BciHbZG4rbrswAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle 0.0874989834394464$"
      ],
      "text/plain": [
       "0.0874989834394464"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = cos(2*x)\n",
    "expr.evalf(subs={x: 2.4})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有时在计算表达式之后, 会出现小于所需精度的舍入错误. 这个时候可以使 `chop` 为 `True` 来避免这种错误. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHIAAAATCAYAAABMdVmCAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADj0lEQVRoBe2a3VEcMQyAgaEAQjqADiB0AB0AqQDoACZvvGVIB0AJSQchFRDoIHQAoYPL9y32jne55bzZH+7hNGMsy1pJK8my18fyZDJZWsB4Hjg/P19D2yHtBHw71RzmvgTaRuiPoD+nfBGHfhdlrEbioh/eAzh9Cy27QZMBrcMFPCeRCH4JfkfbjLTYM3cKrrwCViKy6If3AM6/p31D00ODtmPmY6BluaBtQCsDJjHwVGQsAqln5gdcjb/fMocgupIN7E3Ktwhk6o13xgnSFS3dDw3sA7T7xDRXrau6AoPskSgyY9zMy3pf0TplAK9lRHikuSe4X1TKh5N9QLDvO7K2wVPHleLHtKdUmiDBxn1tjGRojn/EcdoPEkgU6KQ0i1Kdr3AMdEP/Sl8YSW/58ES2R+slmEHmNXKfaJ9o8VQIWgV4Z9oDj8kak68qoDoyoVu9A/zapuwy0QJtvUlW74FEkaepbID/GOY1+jLTwJ/D2FPbXrawNxiVyfSBLOCVE1/6GHNZ9sBnovZiW01/EUTkF7LpTRhtN7k3GcfkcbwUxre9BjJRquJc0LnTVu8t9FNkGuQ28nL1NvG9mz28p0E0ec+CL7XR7cmxq7r0U+A16axkzysgfcJnhF61FLgLv+WuDjF4zo8Jg9mj82muKD/6xS9paQWzpKvfPjYPN9EXkItVaAANuHDN/P7qC979bzAoCs8SyDNrGYzrGTy9sAxtD/JdVWdNxjL/oWkupcPnYqksmF5WJIItCe5rrTZ1nolBqmRcMDqu0pxgh0c6d/NmT/YL9RJItHkyq2RItgWzGT/OZhmVY97sKV5+lQCY8b9obTL/gOeKjZc+rddtPRpX3bTn4up4nDYpLdj+F9Srr/J7q4k/g97Jngz5g7EYSMvafzmBZy2pnirbltTihdRNE5+WRJHWKDs87/yb11oqyIGu9uToGIqn62HHQO7gAC8AUthi4KlMuldMjRs8894ZKqcOcUVW7hTrTMh+9ctAnafluJM9LXX1xt4pkDjRl37laOiWuxv64gN8hrUGO37kpqxWCUumFWNMmDd7st69r8NOXZllMZbGYo6AWIInNL+PSmDsIemJ3nvEAsB99pB29EIZ7++82ZP75st9/ocATvA70ntMS6vgav0Jvbitp/8jjb5ymc7YwPmRHA82O+DeWBQHKvBeAHmuNnVpo737qzpumSt/URjLHvT2Bv8AnWtr3wv8Q/QAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle -4.0 \\cdot 10^{-124}$"
      ],
      "text/plain": [
       "-0.e-124"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "one = cos(1)**2 + sin(1)**2\n",
    "(one - 1).evalf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOCAYAAAAWo42rAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA0UlEQVQoFXWR0Q2CQBBEhVgAwQ60BLUCsQO0A+3BP/4MJWgLWgIdGCmBDiB2gG+OW0PIuckyO3Ozu5cj6vt+ZlEURenrFlyRJVojLTIjwht+BZ86ABNA2p66ib14BhMzee0Dqukm7ozggawlTOIFzzTdjBlCNzGJaqoii/1dBvr/m2pi6s+te2y3Lb/V48NQvdBE6woZbFurO9rKJOA0bXhHDBW5DBhtYmXP88C0CRjXaLW2OiPFHaEDczNTa+2RPEmb6+ND3RcMdoUtfAd3f+wLrOY/XeyA6s8AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle 0$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(one -  1).evalf(chop=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### lambdify\n",
    "\n",
    "如果需要在多个点计算表达式的估计值, 需要使用 `lambdify` 函数. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.        ,  0.84147098,  0.90929743,  0.14112001, -0.7568025 ,\n",
       "       -0.95892427, -0.2794155 ,  0.6569866 ,  0.98935825,  0.41211849])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.arange(10)\n",
    "expr = sin(x)\n",
    "f = lambdify(x, expr, \"numpy\")\n",
    "f(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Words\n",
    "\n",
    "| 英文 | 词性 | 中文 | \n",
    "| - | - | - | \n",
    "| immutable | adj. | 不可改变的 | \n",
    "| round off | | 四舍五入 | "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
